﻿Imports System.Xml
Imports System.IO
Public Class DocXML
    Public Function LoadXMLDocument() As XDocument
        Return XDocument.Load("Books.xml")
    End Function
    Public Function LoadXML() As DataTable
        Dim reader As XmlTextReader = New XmlTextReader("Books.xml")
        Dim doc As XDocument = LoadXMLDocument()
        Dim dtb As New DataTable
        dtb.Columns.Add("id")
        dtb.Columns.Add("author")
        dtb.Columns.Add("title")
        dtb.Columns.Add("genre")
        dtb.Columns.Add("price")
        dtb.Columns.Add("publish_date")
        dtb.Columns.Add("description")
        For Each p As XElement In doc.Descendants("book")
            Dim row As DataRow = dtb.NewRow()
            row(0) = p.Attribute("id").Value
            row(1) = p.Element("author").Value
            row(2) = p.Element("title").Value
            row(3) = p.Element("genre").Value
            row(4) = p.Element("price").Value
            row(5) = p.Element("publish_date").Value
            row(6) = p.Element("description").Value
            dtb.Rows.Add(row)
        Next
        Return dtb
    End Function




End Class
